package com.xiaoshuidi.cloud.module.contract.dal.mysql.roommeta;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.framework.mybatis.core.query.QueryWrapperX;
import com.xiaoshuidi.cloud.module.contract.controller.admin.roommate.vo.ContractRoommatePageReqVO;
import com.xiaoshuidi.cloud.module.contract.controller.admin.roommate.vo.ContractRoommatePageRespVO;
import com.xiaoshuidi.cloud.module.contract.dal.dataobject.roommeta.ContractRoommateDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 合同同住人数据 Mapper
 *
 * @author test123
 */
@Mapper
public interface ContractRoommateMapper extends BaseMapperX<ContractRoommateDO> {


    IPage<ContractRoommatePageRespVO> pageCompanyRoommateList(Page<ContractRoommatePageRespVO> page, @Param("pageReqVO") ContractRoommatePageReqVO pageReqVO);

    default int deleteByContractId(Long roomContractId) {
        return delete(new QueryWrapperX<ContractRoommateDO>()
                .eq("room_contract_id", roomContractId));
    }
    @Select("select * from contract_roommate " +
            "where room_contract_id = #{contractId}" +
            "and status <> 3 and deleted = 0")
    List<ContractRoommateDO> selectRoommateListByContractId(@Param("contractId")Long contractId);

    @Update("update contract_roommate set status = 2 where room_contract_id = #{contractId} and contract_customer_type='personal'")
    void handleRoommateCheckIn(@Param("contractId")Long contractId);

    @InterceptorIgnore(tenantLine = "true")
    List<Long> countRoomHeadsByRoomIds(@Param("roomIds")List<Long> roomIds);

    @Select("select roommate_phone from contract_roommate where room_contract_id = #{contractId} and status = 2 and deleted = 0")
    List<String> selectByContractId(@Param("contractId") Long contractId);

    @Select("select * from contract_roommate where room_contract_id = #{contractId} and status = 2 and deleted = 0")
    List<ContractRoommateDO> selectCheckInByContractId(@Param("contractId") Long contractId);

    @Select("select roommate_phone from contract_roommate where room_contract_id = #{contractId}  and deleted = 0")
    List<String> selectByContractIdWithOutStatus(@Param("contractId") Long contractId);

    List<ContractRoommateDO> selectAllCompanyCheckinRoom(Long memberId);

    void updateMemberUser(@Param("userId")Long userId, @Param("mobile")String mobile, @Param("userName")String userName,@Param("oldUserId") Long oldUserId);
}
